package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.album.client.AlbumInfoFeignClient;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.album.AlbumDetailVo;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class SearchApiController {
    @Resource
    private SearchService searchService;


    @GetMapping("channel/{category1Id}")
    @Operation(summary = "根据一级分类查询热门三级分类的热门专辑")
    public Result<List<Map<String, Object>>> channel(@PathVariable Long category1Id) {
        List<Map<String, Object>> list = searchService.channel(category1Id);
        return Result.ok(list);
    }

    @PostMapping
    @Operation(summary = "根据条件查询专辑")
    public Result<AlbumSearchResponseVo> search(@RequestBody AlbumIndexQuery query) {
        AlbumSearchResponseVo albumSearchResponseVo = searchService.search(query);
        return Result.ok(albumSearchResponseVo);
    }

    @GetMapping("/findRankingList/{category1Id}/{field}")
    @Operation(summary = "获取排行榜列表")
    public Result<List<AlbumInfoIndexVo>> findRankingList(@PathVariable Long category1Id, @PathVariable String field) {
        List<AlbumInfoIndexVo> albumInfoIndexVoList = searchService.findRankingList(category1Id, field);
        return Result.ok(albumInfoIndexVoList);
    }

    @GetMapping("{albumInfoId}")
    @Operation(summary = "根据专辑id查询专辑详情")
    public Result<AlbumDetailVo> searchAlbumDetail(@PathVariable Long albumInfoId) {
        AlbumDetailVo albumDetailVo = searchService.searchAlbumDetail(albumInfoId);
        return Result.ok(albumDetailVo);
    }

    @GetMapping("completeSuggest/{keyword}")
    @Operation(summary = "根据关键字查询相关推荐")
    public Result<List<String>> completeSuggest(@PathVariable String keyword) {
        List<String> keywordList = searchService.completeSuggest(keyword);
        return Result.ok(keywordList);
    }

    @PostMapping("updateRankingData")
    public Result updateRankingData() {
        this.searchService.updateRankingData();
        return Result.ok();
    }
}

